<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl"
                class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
                style="touch-action:pan-y;">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id==0?'mui-active':'']" v-for="item in list" :key="item.id"
                        @click="getList(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
        <ul class="imgList">
            <router-link v-for="item in data" :key="item.id" :to="'/index/photos/photosInfo/'+item.id" tag="li">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h6>{{item.title}}</h6>
                    <span>
                        {{item.zhaiyao}}
                    </span>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
    import {
        toast
    } from 'mint-ui';
    import mui from '../../lib/mui/dist/js/mui.min.js'
    export default {
        data() {
            return {
                data: [],
                list: []
            }
        },
        methods: {
            getData() {
                this.$http.get('api/getimgcategory').then(res => {
                    if (res.body.status == 0) {
                        this.list = res.body.message;
                        this.list.unshift({
                            title: '全部',
                            id: '0'
                        });
                    } else {
                        toast('获取数据失败');
                    }
                });
            },
            getList(id) {
                this.$http.get(`api/getimages/${id}`).then(res => {
                    if (res.body.status == 0) {
                        this.data = res.body.message;
                    } else {
                        toast('获取图片失败');
                    }
                });
            },
        },
        created() {
            this.getData();
            this.getList(0);
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            })
        },
    }
</script>
<style lang="less" slot-scope>
    .imgList {
        list-style: none;
        padding: 10px;
        padding-bottom: 0;
        margin: 0;

        li {
            margin-bottom: 10px;
            box-shadow: 0 0 6px #999;
            position: relative;
        }

        img {
            width: 100%;
            margin: 0 auto;
            display: block;
        }

        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }

        .info {
            position: absolute;
            bottom: 0;
            left: 0;
            font-size: 12px;
            max-height: 100px;
            background-color: rgba(0, 0, 0, .4);
            color: #ccc;
            overflow: hidden;
            h6 {
                font-size: 12px;
                text-align: left;
                margin: 0;
                color: #ccc;
            }
            span {
                display: block;
                text-align: left;
                line-height: 14px;
            }
        }
    }
</style>